import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/home/activity/home_activity_page.dart';
import 'package:flutter_douban/main_page/home/recommend/home_recomend_page.dart';
import 'package:flutter_douban/main_page/home/video/home_video_page.dart';
import 'package:flutter_douban/main_page/home/nav_home_page.dart';
import 'package:flutter_douban/tool_views/my_underline_tabIndicator.dart';
import 'anchorbaking/anchor_baking_page.dart';
import 'attention/home_image_page.dart';
import 'mother/home_mother_page.dart';
import 'notes/home_notes_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

const List<Tab> _tabs = [
  Tab(text: '  关注  '),
  Tab(text: '  推荐  '),
  Tab(text: '  笔记  '),
  Tab(text: '  视频  '),
  Tab(text: '  母婴  '),
  Tab(text: '  安佳烘焙  '),
  Tab(text: '  活动  '),
];

final List<Widget> _tabaContent = [
  HomeAttentionPage(),
  HomeRecomendPage(),
  HomeNoteGridPage(),
  HomeVideoPage(),
  HomeMotherPage(),
  AnchorBakingPage(),
  HomeActivityPage(),
];


class _HomePageState extends State<HomePage> with TickerProviderStateMixin{
  late TabController _tabController;
  final PageController pageController = new PageController();
  final ScrollController scrollController = new ScrollController();

  /// 初始化方法 请求数据
  @override
  void initState() {
    super.initState();

    _tabController = TabController(
      length: _tabs.length,
      vsync: this,
      initialIndex: 1, // 默认选中哪一个
    );

    _tabController.addListener(() {
      _tabController.index;
      print('切换了item');
    });
  }

  @override
  void dispose() {
    // 释放对象
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: NavHomePage(),
        backgroundColor: Colors.white,
        bottom: TabBar(
          tabs: _tabs,
          controller: _tabController,
          isScrollable: true,
          indicator: MyUnderlineTabIndicator(
              borderSide: BorderSide(
                  width: 5.0, color: AppColors.yellow)),
          onTap: (index) {
            // setState(() {});
            // scrollController.animateTo(0,
            //     duration: Duration(milliseconds: 100),
            //     curve: Curves.fastOutSlowIn);
            // pageController.jumpToPage(index);
          },
        ),
      ),
      body: Container(
        child: TabBarView(
          children: _tabaContent,
          controller: _tabController,
        ),
      ),
      );
  }
}
